<template>
    <div class="preview">
        <el-breadcrumb>
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item v-breadcrumb-certify></el-breadcrumb-item>
            <!--<el-breadcrumb-item>赛事预览</el-breadcrumb-item>-->
        </el-breadcrumb>
        <match-info  class="divider"
                :data="race_preview_form"></match-info>
        <match-detail
           :data="race_preview_form"></match-detail>
        <div class="button-box">
            <el-button type="primary" @click="goBack">返回编辑</el-button>
            <el-button type="primary" @click="submit()">确认提交</el-button>
        </div>
    </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import MatchDetail from './components/MatchDetail'
  import MatchInfo from './components/MatchInfo'
  import raceApi from 'api/race'
  export default {
    components: {
      MatchInfo,
      MatchDetail
    },
    computed: {
      ...mapGetters({
        race_preview_form: 'race_preview_form',
        race_form: 'race_form'
      })
    },
    methods: {
      goBack () {
        this.$router.go(-1)
      },
      handleSuccess () {
        this.$message('提交成功')
        this.$router.push({path: '/race/release'})
      },
      submit () {
        this.$confirm('确定要提交比赛吗?', '提示', {
          type: 'warning'
        }).then(() => {
          if (this.race_form.matchType == 3006) { // eslint-disable-line
            raceApi.releaseRun(this.race_form, this).then((res) => {
              this.handleSuccess()
            })
          } else {
            raceApi.release(this.race_form, this).then((res) => {
              this.handleSuccess()
            }).catch((err) => {
              this.$message({
                message: err.msg,
                type: 'warning'
              })
            })
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          })
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
    .preview {
        padding-bottom: 1px;
    }
</style>
